require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsGuildAllyHandler = {};
local this = RedDotsGuildAllyHandler;

function RedDotsGuildAllyHandler.init()
    CloseEvent(Config.EventType.Union_AllianceMerge_S2C, this.update);
    ListenEvent(Config.EventType.Union_AllianceMerge_S2C, this.update);
    return this;
end

---公会结盟申请
function RedDotsGuildAllyHandler.getFlag()
    local flag = Config.RedDotsFlagState.None;
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Guild) then
        local unionInfo = logicMgr.GuildManager.unionInfo;
        if unionInfo ~= nil and unionInfo.leader ~= nil then
            if tostring(unionInfo.leader.showInfo.playerId) == tostring(logicMgr.HeroManager.GetRoleInfo().playerId) then
                if logicMgr.GuildManager.applyAllyNum > 0 or logicMgr.GuildManager.hasAllyApply then
                    flag = Config.RedDotsFlagState.Needful;
                end
            end
        end
    end
    return flag;
end

function RedDotsGuildAllyHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.GuildAlly);
end